﻿using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_DriverReportKMModelWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ReportViewer1.LocalReport.EnableHyperlinks = true;
                InitPage();

            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
            
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
        }

        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.EndDate.Text = DateTime.Now.AddMonths(1).ToString("yyyy-MM-01");
            if (Request.QueryString["ReportName"] != null)
            {
                reportName = Request.QueryString["ReportName"];
                ViewState["reportName"] = reportName;
            }
            else
            {
                reportName = "TJ_SJRBGLS.rdlc";
                ViewState["reportName"] = reportName;
            }
            //if (reportName == "TJ_GRXFFSCG.rdlc") { this.StartDate.Text = DateTime.Now.ToString("yyyy-01-01 00:00:00"); }
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string stationID = Convert.ToString(this.Station.Text);
            string name = Convert.ToString(this.Name.Text);
            string State = Convert.ToString(this.State.Text);

            string start1 = beginTime.ToString("yyyy/MM/dd");
            string end1 = endTime.ToString("yyyy/MM/dd");

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("startTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("endTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
      
            LSDAL dalt = new LSDAL();
            endTime = endTime.AddDays(1);
            switch (reportName) {
                case "TJ_SJRBGLS.rdlc"://日报表司机公里数统计            
                    this.Page.Title = "日报表司机公里数统计";
                    DataTable dt1 = dalt.Get_TJ_SJRBGLS(beginTime, endTime, stationID, name, State);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_SJRBGLS", dt1));
                    break;
                case "TJ_SJRBYSGLS.rdlc"://日报表医生公里数统计            
                    this.Page.Title = "日报表医生公里数统计";
                    DataTable dt2 = dalt.Get_TJ_SJRBYSGLS(beginTime, endTime, stationID, name, State);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_SJRBYSGLS", dt2));
                    break;
                case "TJ_SJRBDJGGLS.rdlc"://日报表担架工公里数统计            
                    this.Page.Title = "日报表担架工公里数统计";
                    DataTable dt3 = dalt.Get_TJ_SJRBDJGGLS(beginTime, endTime, stationID, name, State);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_SJRBDJGGLS", dt3));
                    break;
                default:
                    break;     
            }
    

            this.ReportViewer1.LocalReport.Refresh();
        }



    }
}